<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Art extends Model
{
    use HasFactory;
	
	protected $primaryKey = 'art_id';
	//content字段定义为延迟加载
	protected $lazyLoad = ['content'];
	
	protected $casts = [
        'created_at'   => 'datetime:Y-m-d H:i:s',
        'updated_at'   => 'datetime:Y-m-d H:i:s',
    ];
	
	public function comments()
    {
		//第一个art_id是评论表的文章id(外键)，第二个是文章表id(本地键)
        return $this->hasMany(Comment::class,'art_id','art_id')
			->select('comment_id','fcomment_id','comment','username','user_id','zan','created_at')->where('status',1);
    }
	
}
